var t, e = require("../../../../../@babel/runtime/helpers/defineProperty"), o = getApp();

Page((t = {
    data: {
        value: "2018-11-11",
        week: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
        lastMonth: "lastMonth",
        nextMonth: "nextMonth",
        selectVal: "",
        store_id: "",
        worker_id: "",
        showStore: !1,
        showDefault: !1,
        show1: !1,
        choose_end: "00:00",
        choose_start: "00:00",
        isDefault: 0,
        even_true: !1
    },
    onLoad: function(t) {
        if (console.log(t), t.worker_id && this.setData({
            worker_id: t.worker_id
        }), t.item) {
            var e = JSON.parse(t.item);
            this.setData({
                store_id: e.id
            });
            var o = {
                id: e.id,
                store_name: e.name
            };
            this.choose(o, "1");
        } else this.setData({
            even_true: !0
        });
    },
    getStore: function(t) {
        console.log(t), this.setData({
            showStore: !0
        }), this.getStore();
    },
    showStoreCloseBtn: function() {
        this.setData({
            showStore: !1
        });
    },
    choose: function(t, e) {
        console.log(t), e ? this.setData({
            chooseStore: t,
            showStore: !1
        }) : this.setData({
            chooseStore: t.currentTarget.dataset.item,
            showStore: !1,
            even_true: !1
        }), console.log(this.data.chooseStore), console.log(this.data.chooseStore.id), this.getDefaultTime(), 
        this.getAllService(), this.getService();
    },
    addDefaultTime: function() {
        this.setData({
            showDefault: !0,
            isDefault: 1
        }), console.log(this.data.showDefault);
    },
    showDefaultCloseBtn: function(t) {
        var o = (t.target.dataset || t.currentTarget.dataset).v;
        this.setData(e({}, o, !1));
    },
    addTime: function(t) {
        this.setData({
            showDay: !0,
            isDefault: 2
        });
    },
    editTime: function(t) {
        var e = t.currentTarget.dataset.item;
        e && e.work_hour_start && this.setData({
            choose_start: e.work_hour_start,
            choose_end: e.work_hour_end,
            isDefault: 0,
            period_id: e.id
        }), this.setData({
            show1: !0,
            showDay: !1,
            showDefault: !1
        });
    },
    bindTimeChange: function(t) {
        this.setData({
            choose_start: t.detail.value
        });
    },
    bindTimeEndChange: function(t) {
        this.setData({
            choose_end: t.detail.value
        });
    },
    submitTime: function(t) {
        var e = this;
        console.log(this.data.worker_id);
        var a = {}, s = "";
        1 === this.data.isDefault ? (s = "plugin.appointment.frontend.work-time.add-default-period", 
        a = {
            store_id: this.data.chooseStore.id,
            worker_id: this.data.worker_id,
            work_hour_start: this.data.choose_start,
            work_hour_end: this.data.choose_end
        }) : 2 == this.data.isDefault ? (s = "plugin.appointment.frontend.work-time.add-date-period", 
        a = {
            store_id: this.data.chooseStore.id,
            worker_id: this.data.worker_id,
            work_hour_start: this.data.choose_start,
            work_hour_end: this.data.choose_end,
            work_date: this.data.today
        }) : (s = "plugin.appointment.frontend.work-time.edit-date-period", a = {
            period_id: this.data.period_id,
            work_hour_start: this.data.choose_start,
            work_hour_end: this.data.choose_end
        });
        var i = this, r = o.getNetAddresss(s);
        o._getNetWork({
            url: r,
            data: a,
            success: function(t) {
                var o = t.data;
                1 == o.result ? (console.log(o.data), i.setData({
                    show1: !1,
                    choose_start: "",
                    choose_end: ""
                }), 1 === i.data.isDefault ? e.getDefaultTime() : e.getService(), wx.showToast({
                    title: o.msg,
                    duration: 1e3,
                    icon: "none"
                })) : wx.showToast({
                    title: o.msg,
                    icon: "none"
                });
            }
        });
    },
    deleteTime: function(t) {
        var e = t.currentTarget.dataset.date, a = this, s = o.getNetAddresss("plugin.appointment.frontend.work-time.del-default-period");
        o._getNetWork({
            url: s,
            data: {
                time_id: e.id
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.getDefaultTime(), wx.showToast({
                    title: e.msg,
                    icon: "none"
                })) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            }
        });
    },
    changeStatus: function(t) {
        var e = this, a = t.currentTarget.dataset.item, s = o.getNetAddresss("plugin.appointment.frontend.work-time.change-status-by-id");
        o._getNetWork({
            url: s,
            data: {
                period_id: a.id,
                status: t.detail.value ? "0" : "1"
            },
            success: function(t) {
                var o = t.data;
                1 == o.result ? (e.getService(), wx.showToast({
                    title: o.msg,
                    icon: "none"
                })) : wx.showToast({
                    title: o.msg,
                    icon: "none"
                });
            }
        });
    },
    changeDayStatus: function(t) {
        var e = this, a = o.getNetAddresss("plugin.appointment.frontend.work-time.change-status-by-date");
        o._getNetWork({
            url: a,
            data: {
                store_id: this.data.chooseStore.id,
                worker_id: this.data.worker_id,
                work_date: this.data.today,
                status: t.detail.value ? "0" : "1"
            },
            success: function(t) {
                var o = t.data;
                1 == o.result ? (e.getService(), wx.showToast({
                    title: o.msg,
                    icon: "none"
                })) : wx.showToast({
                    title: o.msg,
                    icon: "none"
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    select: function(t) {
        console.log(t);
        var e = t.detail.work_date;
        this.setData({
            today: e
        }), this.getService();
    },
    getAllService: function() {
        var t = this, e = o.getNetAddresss("plugin.appointment.frontend.work-time.get-worker-dates-by-store-id");
        o._getNetWork({
            url: e,
            data: {
                store_id: this.data.chooseStore.id,
                worker_id: this.data.worker_id
            },
            success: function(e) {
                var o = e.data;
                if (1 == o.result) {
                    console.log(o.data);
                    var a = o.data, s = [];
                    a.forEach(function(t, e, o) {
                        s.push(t.work_date_format);
                    }), t.setData({
                        events: s
                    });
                } else wx.showToast({
                    title: o.msg,
                    icon: "none"
                }), console.log(o.msg);
            }
        });
    },
    getService: function() {
        var t = this, e = o.getNetAddresss("plugin.appointment.frontend.work-time.get-period-list-by-date");
        o._getNetWork({
            url: e,
            data: {
                store_id: t.data.chooseStore.id,
                worker_id: t.data.worker_id,
                work_date: this.data.today
            },
            success: function(e) {
                var o = e.data;
                1 == o.result ? (console.log(o.data), t.setData({
                    day_time: o.data.period_list,
                    isRest: o.data.worker_status
                })) : (wx.showToast({
                    title: o.msg,
                    icon: "none"
                }), console.log(o.msg));
            }
        });
    }
}, e(t, "getStore", function(t) {
    var e = this, a = o.getNetAddresss("plugin.appointment.frontend.store.get-list-by-worker-uid");
    o._getNetWork({
        url: a,
        data: {
            member_u_id: this.options.muid || 0
        },
        success: function(t) {
            var o = t.data;
            1 == o.result ? (console.log(o.data), e.setData({
                store: o.data,
                showStore: !0
            })) : wx.showToast({
                title: o.msg,
                icon: "none"
            });
        }
    });
}), e(t, "getDefaultTime", function(t) {
    console.log(this.data.chooseStore.id);
    var e = this, a = o.getNetAddresss("plugin.appointment.frontend.work-time.get-default-period");
    o._getNetWork({
        url: a,
        data: {
            store_id: this.data.chooseStore.id ? this.data.chooseStore.id : this.data.store_id,
            worker_id: this.data.worker_id
        },
        success: function(t) {
            var o = t.data;
            1 == o.result ? (console.log(o.data), e.setData({
                default_time: o.data
            })) : wx.showToast({
                title: o.msg,
                icon: "none"
            });
        }
    });
}), t));